package com.itheima_002;

import javax.swing.*;

public class PictureFrame extends JFrame {
    public PictureFrame() {
        //初始化窗体
        initFrame();
        //绘制窗体
        paintView();

        this.setVisible(true);
    }
    public void initFrame() {
        //窗体大小
        this.setSize(960, 565);
        //窗体标题
        this.setTitle("动漫拼图");
        //窗体居中
        this.setLocationRelativeTo(null);
        //窗体关闭时退出应用程序
        this.setDefaultCloseOperation(3);
        //窗体位于其他窗体之上
        this.setAlwaysOnTop(true);
        //取消窗体默认布局
        this.setLayout(null);
    }
    //窗体上组件的绘制
    public void paintView() {
        //标题图片
        JLabel titleLabel = new JLabel(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\title.png"));
        titleLabel.setBounds(354, 27, 232, 57);
        this.add(titleLabel);

        //定义一个二维数组，用来存储图片的编号
        int[][] datas = {
                {1, 2, 3, 4},
                {5, 6, 7, 8},
                {9, 10, 11, 12},
                {13, 14, 15, 16}
        };
        //创建面板
        JPanel imagePanel = new JPanel();
        imagePanel.setBounds(150, 114, 360, 360);
        imagePanel.setLayout(null);

        //遍历二维数组，得到图片编号
        for (int i = 0; i < datas.length; i++) {
            for (int j = 0; j < datas[i].length; j++) {
                //创建Jlabel类创建对象，加载图片资源
                JLabel imageLabel = new JLabel(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\" +datas[i][j]+ ".png"));
                imageLabel.setBounds(j*90, i*90, 90, 90);
                imagePanel.add(imageLabel);
            }
        }
        this.add(imagePanel);

        //参照图
        JLabel canzhaoLabel=new JLabel(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\canzhaotu.png"));
        canzhaoLabel.setBounds(574,114,122,121);
        this.add(canzhaoLabel);

        //上下左右按钮 求助按钮 重置按钮
        JButton shangButton=new JButton(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\shang.png"));
        shangButton.setBounds(732,265,57,57);
        this.add(shangButton);

        JButton xiaButton=new JButton(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\xia.png"));
        xiaButton.setBounds(732,347,57,57);
        this.add(xiaButton);

        JButton zuoButton=new JButton(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\zuo.png"));
        zuoButton.setBounds(650,347,57,57);
        this.add(zuoButton);

        JButton youButton=new JButton(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\you.png"));
        youButton.setBounds(813,347,57,57);
        this.add(youButton);

        JButton qiuzhuButton=new JButton(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\qiuzhu.png"));
        qiuzhuButton.setBounds(626,444,108,45);
        this.add(qiuzhuButton);

        JButton chongzhiButton=new JButton(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\chongzhi.png"));
        chongzhiButton.setBounds(786,444,108,45);
        this.add(chongzhiButton);

        //设置背景图
        JLabel backgroundLabel=new JLabel(new ImageIcon("C:\\Users\\Administrator.DESKTOP-88TF7H0\\IdeaProjects\\picture_puzzle\\images\\background.png"));
        backgroundLabel.setBounds(0,0,960,530);
        this.add(backgroundLabel);


    }
}
